<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增支付宝服务商信息')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <th:block th:include="include :: select2-css" />

</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-isvInfo-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">服务商名称：</label>
                <div class="col-sm-8">
                    <input name="isvName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group" style="display: none">
                <label class="col-sm-3 control-label is-required">服务商类型：</label>
                <div class="col-sm-8">
                    <select name="isvType" class="form-control">
                        <option value="0" selected>平台商</option>
                        <option value="1">服务商</option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">支付宝APPID：</label>
                <div class="col-sm-8">
                    <input name="isvAppId" id="isvAppId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">应用公钥证书：</label>
                <div class="col-sm-8">
                    <input id="isvAppPublicKeyFile" name="file" type="file">
                    <input id="isvAppPublicPath" name="isvAppPublicPath" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">支付宝公钥证书：</label>
                <div class="col-sm-8">
                    <input id="isvAliPublicKeyFile" name="file" type="file">
                    <input id="isvAliPublicPath" name="isvAliPublicPath" type="hidden">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">支付宝根证书：</label>
                <div class="col-sm-8">
                    <input id="isvAliRootKeyFile" name="file" type="file">
                    <input id="isvAliRootPath" name="isvAliRootPath" type="hidden">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">商户私钥：</label>
                <div class="col-sm-8">
                    <textarea name="isvAliPrivateKey" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "business/isvInfo"
        $("#form-isvInfo-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-isvInfo-add').serialize());
            }
        }
        $(document).ready(function () {
            // 单图上传  +[[${fileid}]]
            $("#isvAppPublicKeyFile").fileinput({
                uploadUrl: ctx + "common/aliupload/",
                maxFileCount: 1,
                autoReplace: true,
                showPreview: false,
                dropZoneEnabled: false,
                msgPlaceholder: "请选择appCertPublicKey开头的文件",
                uploadExtraData:function(){//向后台传递参数
                    var data={
                        appId:$("#isvAppId").val(),
                    };
                    return data;
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                $("#isvAppPublicPath").val(rsp.fileName);
                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            $("#isvAliPublicKeyFile").fileinput({
                uploadUrl: ctx + "common/aliupload/"+$("#isvAppId").val(),
                maxFileCount: 1,
                autoReplace: true,
                showPreview: false,
                dropZoneEnabled: false,
                msgPlaceholder: "请选择alipayCertPublicKey开头的文件",
                uploadExtraData:function(){//向后台传递参数
                    var data={
                        appId:$("#isvAppId").val(),
                    };
                    return data;
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                $("#isvAliPublicPath").val(rsp.fileName);

                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

            $("#isvAliRootKeyFile").fileinput({
                uploadUrl: ctx + "common/aliupload/"+$("#isvAppId").val(),
                maxFileCount: 1,
                autoReplace: true,
                showPreview: false,
                dropZoneEnabled: false,
                msgPlaceholder: "请选择alipayRootCert开头的文件",
                uploadExtraData:function(){//向后台传递参数
                    var data={
                        appId:$("#isvAppId").val(),
                    };
                    return data;
                },
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                $("#isvAliRootPath").val(rsp.fileName);
                log.info("return url：" + rsp.url)
                log.info("reutrn fileName：" + rsp.fileName)
                log.info("reutrn newFileName：" + rsp.newFileName)
                log.info("return originalFilename：" + rsp.originalFilename)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })

        });
    </script>
</body>
</html>